<!--在线注册-->
<template>
    <div>
        <div style="font-size:23px">在线注册></div>
        <el-alert
            title="请确保信息正确,后台会进行审核！"
            type="success"
            :closable="false">
        </el-alert>
        <el-tabs type="border-card" style="height:500px">
                <el-tab-pane label="学员申请">
                        <el-form label-position="right" label-width="80px" ref="FormStu" :model="FormStu">
                        <el-form-item label="手机号" 
                        prop="tel"
                        :rules="[
                        { required: true, message: '电话不能为空'},
                        ]">
                            <el-input style="width:300px" clearable v-model="FormStu.tel"></el-input>
                        </el-form-item>
                        <el-form-item label="身份证号"
                        prop="idCard"
                         :rules="[
                        { required: true, message: '身份证号不能为空'}
                        
                        ]">
                            <el-input style="width:300px" clearable v-model="FormStu.idCard"></el-input>
                        </el-form-item>
                        <el-form-item label="密码">
                            <el-input type="password" style="width:300px" clearable v-model="FormStu.password"></el-input>
                        </el-form-item>
                         <el-form-item label="确定密码">
                            <el-input type="password" style="width:300px" clearable v-model="FormStu.isPassword"></el-input>
                        </el-form-item>
                        <el-form-item>
                             <el-button @click="submitForm('FormStu')" :loading="loading" type="primary">申 请</el-button>
                        </el-form-item>
                        </el-form>
                </el-tab-pane>

                
                <el-tab-pane label="教练申请">
                    <el-form label-position="right" label-width="80px" ref="FormCoach" :model="FormCoach">
                        <el-form-item label="手机号" 
                        prop="tel"
                        :rules="[
                        { required: true, message: '电话不能为空'},
                        ]">
                            <el-input style="width:300px" clearable v-model="FormCoach.tel"></el-input>
                        </el-form-item>
                        <el-form-item label="身份证号"
                        prop="idCard"
                         :rules="[
                        { required: true, message: '身份证号不能为空'}
                        
                        ]">
                            <el-input style="width:300px" clearable v-model="FormCoach.idCard"></el-input>
                        </el-form-item>

                        <el-form-item label="车牌号"
                         prop="carNum"
                         :rules="[
                        { required: true, message: '身份证号不能为空'}]"
                        >
                            <el-input style="width:300px" clearable v-model="FormCoach.carNum"></el-input>
                        </el-form-item>


                        <el-form-item label="密码">
                            <el-input type="password" style="width:300px" clearable v-model="FormCoach.password"></el-input>
                        </el-form-item>

                         <el-form-item label="确定密码">
                            <el-input type="password" style="width:300px" clearable v-model="FormCoach.isPassword"></el-input>
                        </el-form-item>
                        <el-form-item label="管理科目">
                            <el-input placeholder="2或者3" type="password" style="width:100px" clearable v-model="FormCoach.manSubject"></el-input>
                        </el-form-item>
                        <el-form-item>
                             <el-button @click="submitForm2('FormCoach')" :loading="loading" type="primary">申 请</el-button>
                        </el-form-item>
                        </el-form>
                </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>
export default {
    data () {
        return {
            FormStu:{      //学生
                tel:"",
                password:"",
                idCard:'',
                isPassword:'',
                rid:'2'
            },
            FormCoach:{ //教练
                tel:"",
                idCard:'',
                password:'',
                isPassword:'',
                carNum:'',
                manSubject:'',
                rid:'3'
            },
            loading:false
        }
    },
    methods:  {
            submitForm(formName) { //学员注册
            this.loading = true;
                this.$refs[formName].validate((valid) => {
                if (valid) {
                          if(this.FormStu.password != this.FormStu.isPassword){
                              this.$message.error('密码不一致！')
                              this.loading = false;
                              return ;
                          }
                          this.$api.post("/user/addUserByfront",this.FormStu,Response=>{
                                     if(Response.data.code == 200){
                                         this.FormStu.tel = ''
                                           this.FormStu.idCard = ''
                                          this.$notify.info({
                                                            title: '提示',
                                                            message: "注册成功,等待管理员审核！"
                                                            });
                                           this.loading = false;
                                        
                                     }else{
                                           this.$message.error(Response.data.data);
                                     }
                          })
                } else {
                     this.loading = false;
                    return false;
                }
                });
                setTimeout(()=>{

                    this.loading = false;
                },500)
            },
            submitForm2(formName) {
                this.loading = true;
                this.$refs[formName].validate((valid) => {
                if (valid) {
                          if(this.FormCoach.password != this.FormCoach.isPassword){
                              this.$message.error('密码不一致！')
                              this.loading = false;
                              return ;
                          }
                          this.$api.post("/user/addUserByfront",this.FormCoach,Response=>{
                                     if(Response.data.code == 200){
                                          this.$notify.info({
                                                            title: '提示',
                                                            message: "注册成功,等待管理员审核！"
                                                            });
                                           this.FormCoach.tel = ''
                                           this.FormCoach.idCard=''
                                           this.FormCoach.carNum = ''
                                           this.loading = false;
                                        
                                     }else{
                                           this.$message.error(Response.data.data);
                                     }
                          })
                } else {
                     this.loading = false;
                    return false;
                }
                });
                setTimeout(()=>{

                    this.loading = false;
                },500)
            },
    }
        
    
}
</script>
<style scoped>

</style>
